/*
 * 作者: 张帆
 * 时间: 2017-04-19 
 * 说明：
 * Copyright (c) 2016-2017 中研沃兮
 */
define(function(require) {
	
	require("jquery");

	var c = require('app/utils/CommonUtils');
	var APIUtils = require('app/utils/APIUtils');
	var appInfo = require('app/AppInfo');
	var action_search = require('app/action/SearchIconFrmAction');
	var hc = require('app/utils/HttpClientUtils');
	var EventUtils=require('app/utils/EventUtils');
	var param = api.pageParam;
	
	$("#back").click(function(){
		api.closeWin({
	    });
	});
	
	function getState(){
		var url=appInfo.serverbase+'/luyan/form/list';
		var body={};
		hc.post(url, body, function(resp) {
			if(resp.status == "200"){
				var dom;
				resp.result.forms.forEach(function(item,key){
					dom='<li class="aui-list-item">'+
				            '<div class="aui-list-item-inner">'+
				                '<div class="aui-list-item-title">'+item.name+'</div>'+
				                '<div class="aui-list-item-right">'+
				                	'<div class="aui-btn aui-btn-danger enterpro">进入</div> '+
				                	'<div class="aui-btn aui-btn-warning change">修改</div>'+
				               	'</div>'+
				            '</div>'+
			        	'</li>'
			        $("#enrollpro").append(dom);
			        $("#enrollpro li").eq(key).find(".enterpro").on("click",function(){
			        	var p=param;
			        	p.formid=item.formid;
			        	p.title=item.name;
				        api.openWin({
							name:'EnrollWin',
							url:'./EnrollWin.html',
							pageParam:p,
						})
			        })
			        $("#enrollpro li").eq(key).find(".change").on("click",function(){
			        	var p=param;
			        	p.type="change";
			        	p.title=item.name;
			        	p.formid=item.formid;
				        api.openWin({
							name:'EnrollProDetailsWin',
							url:'./EnrollProDetailsWin.html',
							pageParam:p,
						})
			        })
				})
			}
		})
	}
	getState()
	$("#addData").click(function(){
		var p=param;
		p.type="add";
		api.openWin({
	        name: 'EnrollProDetailsWin',
	        url: './EnrollProDetailsWin.html',
	        pageParam:p
        });	
	})
	EventUtils.listen(api.winName, 'refresh_enrollPro_list', false, function(data){
		location.reload();
	});
	return;
});